package com.omega.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.omega.dao.ItemReceivedDao;
import com.omega.entity.ItemReceived;
import com.omega.service.ItemReceivedService;

@Service
public class ItemReceivedServiceImpl implements ItemReceivedService {

	@Autowired
	ItemReceivedDao itemReceivedDao;

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void addReceiveditem(ItemReceived itemReceived) {
		itemReceivedDao.addReceiveditem(itemReceived);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public List<ItemReceived> loadAllReceivedItems() {
		return itemReceivedDao.loadAllReceivedItems();
	}

	@Override
	public ItemReceived loadById(long itemReceivedId) {
		return itemReceivedDao.loadById(itemReceivedId);
	}

	@Override
	public void updateItemReceived(ItemReceived form) {
		ItemReceived itemReceivedEntity = itemReceivedDao.loadById(form.getitemReceivedId());
		itemReceivedEntity.setBillNo(form.getBillNo());
		itemReceivedEntity.setItem(form.getItem());
		itemReceivedEntity.setNoOfUnits(form.getNoOfUnits());
		itemReceivedEntity.setDenomination(form.getDenomination());
		itemReceivedEntity.setMeasuringUnit(form.getMeasuringUnit());
		itemReceivedEntity.setPricePerUnit(form.getPricePerUnit());
		itemReceivedEntity.setSupplier(form.getSupplier());
		itemReceivedEntity.setTotalWithoutTax(form.getTotalWithoutTax());
		itemReceivedEntity.setTaxes(form.getTaxes());
		itemReceivedEntity.setGrandTotal(form.getGrandTotal());
		itemReceivedEntity.setMonth(form.getMonth());
		itemReceivedEntity.setYear(form.getYear());
		itemReceivedDao.updateItemReceived(itemReceivedEntity);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void deleteItemReceived(long itemReceivedId) {
		itemReceivedDao.deleteItemReceived(itemReceivedId);
		
	}

}
